package com.eppear.jpfm.framework.servlet;

import java.io.IOException;

import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.eppear.jpfm.framework.context.Context;
import com.eppear.jpfm.framework.service.SysStartService;

/**
 * @ClassName SysStartServlet
 * @Description
 *         系统启时的Servlet,用来做全局性的初始化工作
 * @author JianFeng Zhang(张建锋)
 * @date   2016-12-22 下午8:37:46
 *
 */
public class SysStartServlet implements Servlet{

	private static Logger log =LoggerFactory.getLogger(SysStartServlet.class);
	
	@Override
	public void init(ServletConfig config) throws ServletException {
		log.info("---------------【系统正在初始化->启动SysStartServlet】------------");
		ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(config.getServletContext());
		SysStartService sysStartService = context.getBean(SysStartService.class);
		sysStartService.initCache();
		
	}

	@Override
	public ServletConfig getServletConfig() {
		return null;
	}

	@Override
	public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
		
	}
	
	@Override
	public String getServletInfo() {
		return null;
	}

	@Override
	public void destroy() {		
		Context.setCache(null);
	}

}
